package com.seselin.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.example.sorttitleview.R;
import com.seselin.bean.SortItemParam;
import com.seselin.bean.SortTitleBean;
import com.seselin.view.SortTitleView;

import java.util.ArrayList;

/**
 * Created by Seselin on 2018/7/19 14:10.
 * 测试用界面
 */

public class TestSortTitleActivity extends AppCompatActivity {

    private SortTitleView sortTitleView;
    private TextView tvResult;

    private ArrayList<String> titles = new ArrayList<>();
    private ArrayList<SortTitleBean> itemList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sort_title_test);
        sortTitleView = findViewById(R.id.sort_title_view);
        tvResult = findViewById(R.id.tv_result);

        boolean hasHint = false;//是否需要初始化排序

        if (hasHint) {
            hasHintTitle();
        } else {
            simpleTitle();
        }
    }

    private void hasHintTitle() {
        itemList.clear();
        itemList.add(new SortTitleBean("标题1", 1));
        itemList.add(new SortTitleBean("标题2", -1));
        itemList.add(new SortTitleBean("标题3", 1));

        sortTitleView.setItemList(itemList);
        sortTitleView.setOnClickListener(new SortTitleView.OnClickListener() {
            @Override
            public void onConfirmClick(int position, int sortTag) {
                String title = itemList.get(position).getName();
                String sortType = SortTitleBean.getSortName(sortTag);
                tvResult.setText(String.format("%s%s", title, sortType));
            }
        });
    }

    private void simpleTitle() {
        // 数据填充
        titles.clear();
        titles.add("标题1");
        titles.add("标题2");
        titles.add("标题3");
        sortTitleView.setNameList(titles);

        // 样式配置
        SortItemParam itemParam = new SortItemParam()
                .setCheckColor(R.color.sort_title_check);
        sortTitleView.setItemParam(itemParam);

        // 点击事件监听
        sortTitleView.setOnClickListener(new SortTitleView.OnClickListener() {
            @Override
            public void onConfirmClick(int position, int sortTag) {
                String title = titles.get(position);
                String sortType = SortTitleBean.getSortName(sortTag);
                tvResult.setText(String.format("%s%s", title, sortType));
            }
        });

        // 默认选中设置
        sortTitleView.initView(2);
    }
}
